<!--
 * @FilePath     : /study_code/layui/19-1-5.html
 * @Description  : beforeCollapse 和 onCollapse
 * @Date         : 2025-04-13 07:41:03
 * @Author       : Fang YingGui
 * @LastEditors  : fangyinggui 18715384437@163.com
 * @LastEditTime : 2025-04-13 09:14:27
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>documentName</title>
    <link rel="stylesheet" href="/layui/dist/css/layui.css" />
  </head>
  <body>
    <div id="demo"></div>

    <script src="/layui/dist/layui.js"></script>
    <script src="/layui/layui-treetable/common.js"></script>
    <script>
      layui
        .config({
          base: '/layui/extends_modules',
        })
        .extend({
          treetable: '/layui-treetable/treetable',
        })
        .use(['form', 'treetable', 'layer'], function () {
          var layer = layui.layer,
            form = layui.form,
            $ = layui.jquery,
            treetable = layui.treetable

          function treetableBeforeCollapse(node) {
            console.log(3, 'beforeCollapse 父节点折叠之前的回调')
            return true
            // return null
            // return false
          }

          function treetableOnCollapse(node) {
            console.log(4, 'onCollapse 节点被折叠的回调')
            // return null
            // return false
            // return true
          }

          function treetableBeforeExpand() {
            console.log(5, 'beforeExpand 节点被展开之前的的回调')
            // return null
            // return false
            return true
          }

          function treetableOnExpand() {
            console.log(6, 'onExpand 节点被展开的回调')
            // return null
            // return false
            return true
          }

          var tree = layui.treetable({
            elem,
            spreadable,
            checkbox,
            layout,
            nodes,
            // 以上为一个通用的结构

            callback: {
              beforeCollapse: treetableBeforeCollapse,
              onCollapse: treetableOnCollapse,
              beforeExpand: treetableBeforeExpand,
              onExpand: treetableOnExpand,
            },
          })

          form.render()
        })
    </script>
  </body>
</html>
